package com.animationsp.acs.bean;

import java.text.Collator;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

import com.animationsp.acs.util.Constant;

public class ListDir implements Comparable<ListDir> {
	private String dirName; // 目录名
	private long putTime;
	private Date putDate; // 根据putTime生成的日期
	private Set<String> containsFiles; // 目录里面包含的文件的key
	private String orderType; // 排序类型 Constant.SORT_KEY or SORT_DATE or SORT_SIZE
	private String orderASC; // Constant.ORDER_ASC or Constant.ORDER_DESC
	private Collator chCollator = Collator.getInstance(Locale.CHINA);
	
	public ListDir(String dirName){
		this.dirName = dirName;
		chCollator.setStrength(Collator.PRIMARY);
		orderASC = Constant.ORDER_ASC;
		orderType = Constant.SORT_KEY;
	}
	

	public void addFile(String fileKey){
		if(containsFiles == null){
			containsFiles = new HashSet<String>();
		}
		containsFiles.add(fileKey);
	}
	
	@Override
	public int compareTo(ListDir ld) {
		int r = 0;
		if(orderType.equals(Constant.SORT_KEY) || orderType.equals(Constant.SORT_SIZE)){
			r = chCollator.compare(this.getDirName(),ld.getDirName());
		}else if(orderType.equals(Constant.SORT_DATE)){
			r = ((this.putTime - ld.getPutTime())>=0?1:-1);
		}
		return (this.orderASC.equals(Constant.ORDER_ASC)?r:-r);
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof ListDir){
			obj = (ListDir)obj;
			return ((ListDir) obj).dirName.equals(this.dirName);
		}else{
			return false;
		}
	}
	
	@Override
	public String toString() {
		return this.dirName;
	}


	public String getDirName() {
		return dirName;
	}
	public void setDirName(String dirName) {
		this.dirName = dirName;
	}
	public Set<String> getContainsFiles() {
		return containsFiles;
	}
	public void setContainsFiles(Set<String> containsFiles) {
		this.containsFiles = containsFiles;
	}


	public long getPutTime() {
		return putTime;
	}


	public void setPutTime(long putTime) {
		if(putTime > this.putTime){
			this.putTime = putTime;
			this.putDate = new Date(this.putTime / 10000); //putTime的单位是100ns，1纳秒=0.000001毫秒 ，所以换算成毫秒要除以1000
		}
	}


	public Date getPutDate() {
		return putDate;
	}


	public void setPutDate(Date putDate) {
		this.putDate = putDate;
	}


	public String getOrderType() {
		return orderType;
	}


	public void setOrderType(String orderType) {
		this.orderType = orderType;
	}


	public String getOrderASC() {
		return orderASC;
	}


	public void setOrderASC(String orderASC) {
		this.orderASC = orderASC;
	}



}
